#include <bits/stdc++.h>
using namespace std;
int n, a[200005], ans = 0;
vector<int> a1, b1;
void dfs(int step)
{
    if (step == n + 1)
    {
        int ret = 0;
        for (int i = 1; i < a1.size(); ++i)
        {
            if (a1[i] == a1[i - 1]) ret += a1[i];
        }
        for (int i = 1; i < b1.size(); ++i)
        {
            if (b1[i] == b1[i - 1]) ret += b1[i];
        }
        ans = max(ans, ret);
        return;
    }
    a1.push_back(a[step]);
    dfs(step + 1);
    a1.pop_back();
    b1.push_back(a[step]);
    dfs(step + 1);
    b1.pop_back();
}
void solve()
{
    ans = 0;
    cin >> n;
    for (int i = 1; i <= n; ++i) cin >> a[i];
    dfs(1);
    cout << ans << endl;
}
int main()
{
    freopen("color.in", "r", stdin);
    freopen("color.out", "w", stdout);
    int T;
    cin >> T;
    while (T--) solve();
    return 0;
}
/*
struct State
{
    int val;
    vector<int> lst;
}dp[200005][2];
int calc(int x, int y)
{
    return x == y ? x : 0;
}


for (int i = 1; i <= n; ++i)
    {
        dp[i][0].val = dp[i][1].val = 0;
        dp[i][0].lst.clear();
        dp[i][1].lst.clear();
        dp[i][0].lst.push_back(0);
        dp[i][1].lst.push_back(0);
        cin >> a[i];
        s[i] = s[i - 1];
        if (a[i] == a[i - 1]) s[i] += a[i];
    }
    for (int i = 1; i <= n; ++i)
    {
        for (int t = 0; t <= 1; ++t)
        {
            for (int j = 1; j < i; ++j)
            {
                for (int id = 0; id < dp[j][t].lst.size(); ++id)
                {
                    int g1 = dp[j][t].val + calc(a[j + 1], dp[j][t].lst[id]);
                    int g2 = s[i - 1] - s[j + 1] + calc(a[i], a[j]);
                    cout << (i - 1 == j ? dp[j][t].lst[id] : i - 1) << " ";
                    if (g1 + g2 > dp[i][t].val)
                    {
                        dp[i][t].val = g1 + g2;
                        dp[i][t].lst.clear();
                        dp[i][t].lst.push_back((i - 1 == j ? dp[j][t].lst[id] : i - 1));
                    }
                    else if (g1 + g2 == dp[i][t].val)
                    {
                        dp[i][t].val = g1 + g2;
                        dp[i][t].lst.push_back((i - 1 == j ? dp[j][t].lst[id] : i - 1));
                    }
                }
                cout << endl;
            }
            cout << dp[i][t].val << " ";
        }
        cout << endl;
    }
    cout << max(dp[n][0].val, dp[n][1].val) << endl;
*/
